package com.hhkj.admin.order.service.base.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hhkj.admin.order.common.cont.OrderRefundConst;
import com.hhkj.admin.order.domain.OrderRefund;
import com.hhkj.admin.order.model.dopo.OrderRefundDo;
import com.hhkj.admin.order.model.dopo.OrderRefundPo;
import com.hhkj.admin.order.service.base.OrderRefundService;
import com.hhkj.admin.order.mapper.OrderRefundMapper;
import com.ruoyi.common.base.biz.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author admin
* @description 针对表【s_order_refund(记录客户每笔退款的信息)】的数据库操作Service实现
* @createDate 2023-10-27 14:07:42
*/
@Service
public class OrderRefundServiceImpl extends BaseServiceImpl<OrderRefund, OrderRefundDo, OrderRefundPo, OrderRefundMapper>
    implements OrderRefundService{

    @Override
    public Long countByToday() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = simpleDateFormat.format(new Date());
        LambdaQueryWrapper<OrderRefund> queryWrapper = new LambdaQueryWrapper<OrderRefund>()
                .ge(OrderRefund::getCreateTime, date);
        return count(queryWrapper);
    }

    @Override
    public OrderRefundPo getAgreedRefundPo(Long orderId) {
        //查看是否存在正在等待打款的退款
        OrderRefundDo orderRefundDo = new OrderRefundDo();
        orderRefundDo.setOrderId(orderId);
        orderRefundDo.setStatusCode(OrderRefundConst.StatusEnum.REFUNDING.getCode());
        orderRefundDo.setPayoutStatusCode(OrderRefundConst.PayoutStatusCode.PENDING.getCode());
        OrderRefundPo orderRefundPo = getPoByDo(orderRefundDo);
        return orderRefundPo;
    }
}




